package com.pds.web.testOrganization.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pds.common.utils.DateUtils;
import com.pds.common.utils.SecurityUtils;
import com.pds.web.testOrganization.domain.PdsTestOrganizationQualification;
import com.pds.web.testOrganization.mapper.PdsTestOrganizationQualificationMapper;
import com.pds.web.testOrganization.service.IPdsTestOrganizationQualificationService;
import com.pds.web.testOrganizationInfo.domain.PdsTestOrganizationInfo;
import com.pds.web.testOrganizationInfo.mapper.PdsTestOrganizationInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("pdsTestOrganizationQualificationService")
public class PdsTestOrganizationQualificationServiceImpl extends ServiceImpl<PdsTestOrganizationQualificationMapper, PdsTestOrganizationQualification> implements IPdsTestOrganizationQualificationService
{

    @Resource
    private PdsTestOrganizationQualificationMapper pdsTestOrganizationQualificationMapper;

    @Resource
    private PdsTestOrganizationInfoMapper pdsTestOrganizationInfoMapper;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public PdsTestOrganizationQualification addQualification(PdsTestOrganizationQualification pdsTestOrganizationQualification) {

//        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
//        PdsTestOrganizationInfo pdsTestOrganizationInfo = pdsTestOrganizationInfoMapper.selectByUserId(userId);
        Date createTime = DateUtils.parseDate(DateUtils.getTime());
        pdsTestOrganizationQualification.setCreateTime(createTime);
        pdsTestOrganizationQualification.setStatus("1");
//        pdsTestOrganizationQualification.setUserId(userId);
//        pdsTestOrganizationQualification.setOrganizationId(pdsTestOrganizationInfo.getId());
        pdsTestOrganizationQualificationMapper.insertQualification(pdsTestOrganizationQualification);
        return pdsTestOrganizationQualification;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Boolean deleteQualification(Long id) {
        return pdsTestOrganizationQualificationMapper.deleteQualification(id) > 0;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Boolean updateQualification(PdsTestOrganizationQualification pdsTestOrganizationQualification) {
        Date updateTime = DateUtils.parseDate(DateUtils.getTime());
        pdsTestOrganizationQualification.setUpdateTime(updateTime);
        return pdsTestOrganizationQualificationMapper.updateQualification(pdsTestOrganizationQualification) > 0;
    }

    @Override
    public List<PdsTestOrganizationQualification> selectQualificationlist(PdsTestOrganizationQualification pdsTestOrganizationQualification) {
        return pdsTestOrganizationQualificationMapper.selectQualificationlist(pdsTestOrganizationQualification);
    }
}
